﻿package mortal.game.view.skill.panel.render
{
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.display.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import flash.text.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.skill.*;
    import mortal.mvc.core.*;

    public class SkillBasicItem extends GSprite
    {
        private var _bg:GImageBitmap;
        private var _bmpType:GBitmap;
        private var _txtName:GTextFiled;
        private var _skillItem:SkillItem;
        private var _line1:ScaleBitmap;
        private var _txt1:GTextFiled;
        private var _txt2:GTextFiled;
        private var _notGet:GTextFiled;
        private var _selected:Boolean = false;
        private var _selectedEffect:ScaleBitmap;
        private var _skillInfo:SkillInfo;
        public var index:int;
        private static var _loaded:Boolean = false;

        public function SkillBasicItem()
        {
            return;
        }// end function

        public function set selected(param1:Boolean) : void
        {
            this._selected = param1;
            this.updateSelectedView(this._selected);
            return;
        }// end function

        public function get selected() : Boolean
        {
            return this._selected;
        }// end function

        public function updateSelectedView(param1:Boolean = false) : void
        {
            if (param1)
            {
                if (this._selectedEffect == null)
                {
                    this._selectedEffect = UIFactory.bg(0, 0, 132, 204, this, "SkillItemSelectedBg");
                }
            }
            else if (this._selectedEffect != null)
            {
                this._selectedEffect.dispose(true);
                this._selectedEffect = null;
            }
            return;
        }// end function

        public function get skillItem() : SkillItem
        {
            return this._skillItem;
        }// end function

        public function get skillInfo() : SkillInfo
        {
            return this._skillInfo;
        }// end function

        public function set skillInfo(param1:SkillInfo) : void
        {
            this._skillInfo = param1;
            this._skillItem.skillInfo = this._skillInfo;
            this._txtName.text = this._skillInfo.skillName;
            this._txtName.x = 67 - this._skillInfo.skillName.length * 7.5;
            if (this._skillInfo.learned)
            {
                LoaderHelp.setBitmapdata(ImagesConst.skillBasicCellRenderBg + ".swf", this._bg);
                this.removeNotActivedUIs();
                this.addActivedUIs();
                this._skillItem.mouseChildren = true;
                this._skillItem.mouseEnabled = true;
                this._skillItem.filters = [];
                if (this._skillInfo.skillId == GameConst.JPSkillId)
                {
                    this._txt1.htmlText = Language.getStringByParam(21058, "40");
                }
                else if (this._skillInfo.skillId == GameConst.RollingSkillId)
                {
                    this._txt1.htmlText = Language.getStringByParam(21058, "25");
                }
                else
                {
                    this._txt1.htmlText = Language.getStringByParam(21059, this._skillInfo.tSkill.consume);
                }
                this._txt2.htmlText = Language.getStringByParam(20238, SkillUtil.getCoolDownTimeStr(this._skillInfo.tSkill, true));
            }
            else
            {
                LoaderHelp.setBitmapdata(ImagesConst.skillBasicNotLearned + ".swf", this._bg);
                this.removeActivedUIs();
                this.addNotActivedUIs();
                this._skillItem.mouseEnabled = false;
                this._skillItem.mouseChildren = false;
                this._skillItem.filters = [FilterConst.colorFilter];
            }
            this.updateUI();
            return;
        }// end function

        private function updateUI() : void
        {
            if (isDisposed || !_loaded || this._skillInfo == null)
            {
                return;
            }
            this._bmpType.x = 36;
            if (Cache.instance.wizard.XpSkillId == this._skillInfo.tSkill.skillId)
            {
                this._bmpType.bitmapData = GlobalClass.getBitmapData(ImagesConst.SkillPanel_XP);
            }
            else
            {
                this._bmpType.bitmapData = GlobalClass.getBitmapData(ImagesConst.SkillPanel_RCJN);
            }
            return;
        }// end function

        private function upgradeHandler(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.SkillUpgradeReq, this._skillInfo.skillId));
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.mouseChildren = true;
            this.mouseEnabled = true;
            this._bg = UIFactory.gImageBitmap(null, 0, 0, this);
            this._bmpType = UIFactory.bitmap(null, 39, 8, this);
            var _loc_1:* = GlobalStyle.textFormatBai.center();
            this._txtName = UIFactory.gTextField("", 0, 36, 130, 26, this, _loc_1);
            this._txtName.mouseEnabled = false;
            this._txtName.embedFonts = true;
            this._txtName.defaultTextFormat = GlobalStyle.windowTitle;
            this._txtName.selectable = false;
            this._txtName.filters = [FilterConst.titleGradientBevelFilter];
            this._txtName.autoSize = TextFieldAutoSize.LEFT;
            this._txtName.antiAliasType = AntiAliasType.ADVANCED;
            this._skillItem = UICompomentPool.getUICompoment(SkillItem) as SkillItem;
            this._skillItem.toolTipMode = SkillItem.TooltipMode_ShowNext;
            this._skillItem.x = 35;
            this._skillItem.y = 72;
            this._skillItem.setSize(60, 60);
            this._skillItem.isDragAble = true;
            this._skillItem.isShowToolTip = true;
            this.addChild(this._skillItem);
            LoaderHelp.addResCallBack(ResFileConst.skillPanel, this.skillPanelGot);
            return;
        }// end function

        private function skillPanelGot() : void
        {
            _loaded = true;
            this.updateUI();
            return;
        }// end function

        private function addActivedUIs() : void
        {
            var _loc_1:GTextFormat = null;
            if (this._txt1 == null)
            {
                this._line1 = UIFactory.bg(0, 165, 130, 2, this, ImagesConst.SplitLine3);
                _loc_1 = GlobalStyle.textFormatBai;
                _loc_1.align = TextFormatAlign.CENTER;
                this._txt1 = UIFactory.gTextField("", 0, 166, 132, 20, this, _loc_1);
                this._txt1.mouseEnabled = false;
                this._txt2 = UIFactory.gTextField("", 0, 183, 132, 20, this, _loc_1.clone());
                this._txt2.mouseEnabled = false;
            }
            return;
        }// end function

        private function removeActivedUIs() : void
        {
            if (this._line1 != null)
            {
                this._line1.dispose(true);
                this._line1 = null;
            }
            if (this._txt1 != null)
            {
                this._txt1.dispose(true);
                this._txt1 = null;
            }
            if (this._txt2 != null)
            {
                this._txt2.dispose(true);
                this._txt2 = null;
            }
            return;
        }// end function

        private function addNotActivedUIs() : void
        {
            var _loc_1:GTextFormat = null;
            if (this._notGet == null)
            {
                _loc_1 = GlobalStyle.textFormatPutong;
                _loc_1.size = 16;
                _loc_1.color = 6710886;
                this._notGet = UIFactory.gTextField(Language.getString(21061), 32, 165, 220, 26, this, _loc_1);
                this._notGet.mouseEnabled = false;
            }
            return;
        }// end function

        private function removeNotActivedUIs() : void
        {
            if (this._notGet != null)
            {
                this._notGet.dispose(true);
                this._notGet = null;
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._skillInfo = null;
            this.removeActivedUIs();
            this.removeNotActivedUIs();
            this._bg.dispose(param1);
            this._bg = null;
            this._bmpType.dispose(param1);
            this._bmpType = null;
            this._txtName.dispose(param1);
            this._txtName = null;
            this._skillItem.dispose(param1);
            this._skillItem = null;
            return;
        }// end function

    }
}
